home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 49
/
Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso
/
-serious-
/
misc
/
charmap
/
source
/
helpwin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-11-30
|
4KB
|
142 lines
/***************************************************************
** helpwin.c: Affiche une fenêtre d'aide sur le caractère **
** Écrit par T.Pierron **
** 15-03-1999 **
***************************************************************/
#include <Intuition/Intuition.H>
#include <Graphics/Rastport.H>
#include <Graphics/Gfxmacros.H>
#include <Exec/Memory.H>
#define CATCOMP_STRINGS
#include "cmap_strings.h"
WORD I;
/**** Cette fonction, extrêmement importante, permet d'allouer *****
***** un nouvel affichage sans être obligé d'ouvrir une fenê- *****
***** tre, avec les lourdeurs qui suivent. ****/
struct RastPort *Alloc_rastport( WORD larg,WORD haut,WORD depth )
{
static struct RastPort *RP;
static struct BitMap *BM;
static Point *P;
/* Alloue les trois structures: */
if( (RP=(void *) AllocMem(sizeof(struct tPoint)+sizeof(struct RastPort)+sizeof(struct BitMap),MEMF_PUBLIC))==NULL )
return NULL;
/* Sauvegarde quelques données: */
BM = (struct BitMap *) (RP+1);
P = (Point *) (BM+1);
RP->BitMap = BM; P->x = larg; P->y = haut;
/* Prépare le BitMap: */
InitBitMap( BM, depth, larg, haut );
/* Alloue la mémoire pour le Raster: */
for( I = 0; I < depth; I++ )
{
if( (BM->Planes[ I ] = (PLANEPTR) AllocRaster( larg, haut ))==NULL )
return NULL;
/* Efface la mémoire avec l'aide du Blitter: */
BltClear( BM->Planes[ I ], RASSIZE( larg, haut ), 0 );
}
/* Prépare le RastPort, en donnant un pointeur sur le BitMap. */
InitRastPort( RP );
RP->BitMap = BM;
return RP;
}
static struct RastPort *RPW=NULL;
extern struct RastPort *RP,RPT;
/**** Libère l'affichage alloué avec la fonction ci-dessus: ****/
void Free_helpwin()
{
register struct BitMap *BM;
register Point *P;
register WORD depth;
if(RPW) {
/* Libère les bitplans un à un: */
for( I = 0,BM = RPW->BitMap,depth = BM->Depth,P = (Point *)(BM+1); I < depth; I++ )
if( BM->Planes[ I ] )
FreeRaster( BM->Planes[ I ], P->x, P->y );
/* Et la mémoire pour les structures de données: */
FreeMem(RPW,sizeof(struct tPoint)+sizeof(struct RastPort)+sizeof(struct BitMap));
RPW=0;
}
}
UBYTE *popmsg[]={ MSG_CODE_STR,MSG_DEC_STR,MSG_HEX_STR,MSG_OCT_STR,0 };
UBYTE *NoMem =MSG_NOMEM_STR;
static WORD WinW,WinH,Larg,X,Y;
extern UBYTE Font_height;
/**** Calcule la largueur et la hauteur de la fenêtre en fonction de la police: ****/
void Init_helpwin()
{
extern struct Screen *screen;
register UBYTE **p;
for(p=popmsg,Larg=0,WinH=3; *p; p++,WinH += Font_height-3)
if(Larg < (WinW=TextLength(&RPT,*p,strlen(*p)))) Larg = WinW;
Larg += 10; WinW = Larg+5+TextLength(&RPT,"999",3); /* WinH -= 9; */
if( !(RPW=Alloc_rastport(WinW,WinH,screen->BitMap.Depth)) )
cleanup(NoMem,30);
}
/**** Conversion binaire => Base ****/
void convert_to_base(UBYTE *Str,UBYTE Var,BYTE Base)
{
UBYTE ChConv[]="0123456789ABCDEF";
UBYTE *ptr=Str,L=0;
Var &= 0xFF;
do {
ptr--; L++;
*ptr = ChConv[ Var%Base ];
} while(Var /= Base);
Text(RP,ptr,L);
}
/**** Affiche toute les infos de la fenêtre: ****/
void Open_helpwin(UBYTE Num,WORD x,WORD y)
{
extern struct Window *window;
extern WORD txtpen,filltxt;
static UBYTE Str[6];
int i;
if(x+WinW>window->Width) x=window->Width-WinW;
if(y+WinH>window->Height) y=window->Height-WinH;
/* Sauvegarde l'affichage de la fenêtre: */
ClipBlit(RP,x,y,RPW,0,0,WinW,WinH,0xC0);
SetOPen(RP,txtpen); SetAPen(RP,filltxt);
RectFill(RP,x,y,x+WinW-1,y+WinH-1);
BNDRYOFF(RP); SetAPen(RP,txtpen);
X=x; Y=y;
for(i=0,y+=Font_height-4; i<sizeof(popmsg)/sizeof(UBYTE *)-1; i++,y+=Font_height-3)
{
Move(RP,x+5,y); Text(RP,popmsg[i],strlen(popmsg[i])); Move(RP,x+Larg,RP->cp_y);
if(i==0) Text(RP,&Num,1);
else convert_to_base(Str+6,Num,i==1? 10 : i==2? 16 : 8);
}
}
void Close_helpwin()
{
ClipBlit(RPW,0,0,RP,X,Y,WinW,WinH,0xC0);
}